package com.zm.oes.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zm.oes.entity.FillQuestion;
import com.zm.oes.entity.JudgeQuestion;
import com.zm.oes.entity.MultiQuestion;
import com.zm.oes.vo.AnswerVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AnswerMapper {

    /**
     * 根据题目、科目和章节模糊查询不同类型（选择题、判断题、填空题）的题目，并将它们合并在一起返回
     * 查询语句使用了三个 union 子句，分别从不同的题目表中查询符合条件的题目。每个 union 子句都是一个独立的 select 查询，使用了 like 条件进行模糊查询，并指定了返回的结果类型为 AnswerVO
     * 参数 subject、section 和 question 分别用于指定查询条件中的科目、章节和题目内容，并通过 @Param 注解进行了映射
     * 最终，使用了IPage<AnswerVO> 作为返回类型，表示返回的结果是一个分页的 AnswerVO 对象列表
     */
    @Select("select questionId, question, subject, score, section,level, \"选择题\" as type from " +
            "multi_question where question like concat('%',#{question},'%') and subject like " +
            "concat('%',#{subject},'%') and section like concat('%',#{section},'%')" +
            "union select questionId,question, subject, score, section,level, \"判断题\" as type  from " +
            "judge_question where question like concat('%',#{question},'%') and subject like " +
            "concat('%',#{subject},'%') and section like concat('%',#{section},'%')" +
            "union select questionId,question, subject, score, section,level, \"填空题\" as type from " +
            "fill_question where question like  concat('%',#{question},'%') and subject like " +
            "concat('%',#{subject},'%') and section like concat('%',#{section},'%')")
    IPage<AnswerVO> findAll(Page<AnswerVO> page, @Param("subject") String subject, @Param("section") String section, @Param("question") String question);


    /**
     * 查选择题
     * @param questionId 选择题id
     * @return 选择题
     */
    @Select("select questionId, subject, question, answerA, answerB, answerC, answerD, rightAnswer, " +
            "section, level, analysis from multi_question where questionId = #{questionId}")
    MultiQuestion findMultiQuestionById(Long questionId);

    /**
     * 查填空题
     *
     * @param questionId 题目id
     * @return 填空题
     */
    @Select("select questionId, subject, question, answer, analysis, level, section from " +
            "fill_question where questionId = #{questionId}")
    FillQuestion findFillQuestionById(Long questionId);

    /**
     * 查判断题
     *
     * @param questionId 题目id
     * @return 判断题
     */
    @Select("select questionId, subject, question, answer, analysis, level, section " +
            "from judge_question where questionId = #{questionId}")
    JudgeQuestion findJudgeQuestionById(Long questionId);
}
